package com.example.minzhengtong.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.example.minzhengtong.Const
import com.example.minzhengtong.HttpRequest
import com.example.minzhengtong.base.BaseA
import com.example.minzhengtong.data.UserBean
import com.example.minzhengtong.databinding.ActivitySecondBinding
import com.example.minzhengtong.utils.SpUtil
import com.google.gson.Gson
import com.gyf.immersionbar.ImmersionBar

/**
 * created by WY on 2021/6/2.
 */
class SecondA : BaseA() {

    companion object{
        fun enterThis(context: Context){
            val intent = Intent(context,SecondA::class.java)
            context.startActivity(intent)
        }
    }

    private lateinit var binding : ActivitySecondBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySecondBinding.inflate(layoutInflater)
        setContentView(binding.root)
        setToolBarVisiabale(false)

        ImmersionBar.with(this).statusBarDarkFont(true).titleBar(binding.titleBar).init()

        if (SpUtil.getInstance().existKey(Const.USER_BEAN)){
            val bean = SpUtil.getInstance().getObject(Const.USER_BEAN) as UserBean
            binding.name.text = bean.data.uname
        }else{
            HttpRequest().detail(baseContext)
        }

    }

    override fun requestSuccess(json: String) {
        super.requestSuccess(json)
        val bean = Gson().fromJson(json, UserBean::class.java)
        binding.name.text = bean.data.uname
    }


}